#include"../file_h/read_file.h"
void read_max(){
    int fd=open("../max_score.txt", O_RDWR);//可读可写
    if(fd<0){
        printf("open file error\n");
        exit(1);
    }
    char buf[32];
    ssize_t len=read(fd,buf,sizeof(buf)-1);
    if(len<0){
        printf("read file error\n");
        exit(1);
    }
    buf[len]='\0';
    max_score=atoi(buf);
    close(fd);
}

void change_max(){
    int fd=open("../max_score.txt", O_RDWR);//可读可写
    if(fd<0){
        printf("open file error\n");
        exit(1);
    }
    char buf[32];
    if(score>max_score){
        snprintf(buf,sizeof(buf),"%d",score);
        lseek(fd,0,SEEK_SET);
        write(fd,buf,strlen(buf));
        ftruncate(fd,strlen(buf));
        close(fd);
        return;
    }

}
